package n1980;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	static int p,q,a,n;
	
	static int ans;
	
	static int comp(int p1,int q1,int p2,int q2)
	{
		return p1*q2-p2*q1;
	}
	
	static void dfs(int lastq,int leftp,int leftq,int num,int product)
	{
		//System.out.println(pre+lastq+","+leftp+","+leftq+","+num+","+product);
		if(num==n&&leftp!=0)return;
		if(num<=n&&leftp==0)
		{
			ans++;
			return;
		}
		for(int i=lastq;i<=product;i++)
		{
			if(comp(leftp,leftq,1,i)<0)continue;//当前1/i比所剩的leftp/leftq要大，则继续增加i
			if(comp(leftp,leftq,n-num,i)>0)break;//(n-num)个1/i的和比leftp/leftq要小，则退出循环
			int curp=leftp*i-leftq;
			int curq=i*leftq;
			dfs(i,curp,curq,num+1,product/i);
		}
	}
	
	/**
	 * @param args
	 */
	public static void main(String[] args)throws Exception {

		BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
		String line=null;
		while((line=bf.readLine())!=null)
		{
			StringTokenizer st=new StringTokenizer(line);
			p=Integer.parseInt(st.nextToken());
			q=Integer.parseInt(st.nextToken());
			a=Integer.parseInt(st.nextToken());
			n=Integer.parseInt(st.nextToken());
			if(p==0&&q==0&&a==0&&n==0)break;
			ans=0;
			dfs(1,p,q,0,a);
			System.out.println(ans);
		}
	}

}
